<?php
/**
 * Invoker
 *
 * Wrapper for methods invocation.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_Invoker extends gop_Base {
    public function execute(gop_Base $_caller = null) {
        if ($this->getReturn()) return;
        $this->setCaller($_caller);
        if (is_null($this->instance) || is_null($this->methodName))
        {
            die("RequiredException: instance, methodName");
        }
        $instance = $this->getContext()->getCallee($this->instance);
        $instance->setCaller($this);
        $z = array($instance, $this->methodName);
        if (!is_callable($z)) {
            die("NoSuchMethodException: ".$z[0]->getName()."::".$this->methodName);
        }
        if (isset($this->arguments)) {$arguments = null;
            if (is_int($this->arguments)) {
                $this->getContext()->getCallee($this->arguments)->execute($this);
                $arguments = $this->getResult();
            } else {
                $arguments = $this->arguments;
            }
            call_user_func_array($z, $arguments);
        } else {
            call_user_func($z);
        }
        $this->chainExec();
    }
}
?>